package com.example.app.Websocket;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import com.example.app.VideoChatActivity;

public class APP extends Application {
    private static WebRTCManager webRTCManager;
    private static String username;
    @Override
    public void onCreate() {
        super.onCreate();
        AppDatabase.getInstance(this);
    }
    public static void initWebRTCManager(Context context, String userName) {
        if (webRTCManager == null) {
            username = userName;
            webRTCManager = new WebRTCManager(context, username, new WebRTCManager.WebRTCListener() {
                @Override
                public void onRemoteStreamAdded() {}
                @Override
                public void onCallReceived(String fromUser) {
                    Intent intent = new Intent(context, VideoChatActivity.class);
                    intent.putExtra("CALL_FROM_USER", fromUser);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(intent);
                }
                @Override
                public void onConnectionEstablished() {}
                @Override
                public void onConnectionClosed() {}
                @Override
                public void onError(String error) {}
            });
        }
    }
    private static DataWebSocketManager dataWebSocketManager;
    public static void initializeDataWebSocket(Context context, String username) {
        if (dataWebSocketManager == null) {
            String dataWsUrl = "wss://" + StaticData.WebSocketHOSTS + "/DataWebSocketServer";
            System.out.println("APP          DataWebSocketServer");
            dataWebSocketManager = new DataWebSocketManager(dataWsUrl);
            dataWebSocketManager.connect(username);
        }
    }
    public static DataWebSocketManager getDataWebSocketManager() {
        return dataWebSocketManager;
    }
    public static WebRTCManager getWebRTCManager() {
        return webRTCManager;
    }
    public static String getUsername() {
        return username;
    }

}